|
|
|
|
|
|
|
'Character list matching
'***********************
SELECT * FROM Customers WHERE MID$(Lastname,1,1) LIKE '[a-f]' |
|
|
|
|
|
|
|
|
The IN predicate lets you determine whether the expression is one of several values. Using the IN predicate, you can check state codes for customers to determine whether the customer's state matches a sales region. This example is shown in the following sample code: |
|
|
|
|
|
|
|
|
SELECT * FROM Customers WHERE State IN ('AL', 'FL', 'GA') |
|
|
|
|
|
|
|
|
Using the BETWEEN Predicate |
|
|
|
|
|
|
|
|
The BETWEEN predicate lets you search for expressions with values within a range of values. You can use the BETWEEN predicate for string, numeric, or date expressions. The BETWEEN predicate performs an inclusive search, meaning that if the value is equal to one of the endpoints of the range, the record is included. You can also use the NOT operator to return records outside the range. The form of the BETWEEN predicate is as follows: |
|
|
|
|
|
|
|
|
expression [NOT] BETWEEN value1 AND value2 |
|
|
|
|
|
|
|
|
Listing C.11 shows the use of the BETWEEN predicate in several scenarios. |
|
|
|
|
|
|
|
|
Listing C.11 BETWEEN.TXTUsing the BETWEEN Predicate to Check an Expression Against a Range of Values |
|
|
|
|
|
|
|
|
'*****************
'String comparison
'*****************
SELECT * FROM Customers WHERE Lastname BETWEEN 'M' AND 'W'
'******************
'Numeric comparison
'******************
SELECT * FROM [Retail Items] WHERE Retail BETWEEN 1 AND 2.5
'***************
'Date comparison
'***************
SELECT * FROM Sales WHERE Date BETWEEN #8/01/94# AND #8/10/94#
'***********************
'Use of the NOT operator
'***********************
SELECT * FROM Customers WHERE Lastname NOT BETWEEN 'M' AND 'W' |
|
|
|
|
|
|
|
|
Combining Multiple Conditions |
|
|
|
|
|
|
|
|
The WHERE clause can also accept multiple conditions so that you can specify filtering criteria on more than one field. Each individual condition of the multiple conditions is in the form of the conditions described in the preceding sections on using predicates. These individual conditions are then combined using the logical operators AND and OR. By using multiple-condition statements, you can find all the Smiths in the Southeast, or you can find anyone whose first or last name is Scott. Listing C.12 shows the statements for these examples. Figure C.6 shows the recordset resulting from a query search for Scott. |
|
|
|
|
|